import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout'
import { storeManage } from './module/storeManage'
import { areaManage } from './module/areaManage'
import { orderManage } from './module/orderManage'
import { couponManage } from './module/couponManage'
import { materialManage } from './module/materialManage'
import { financeManage } from './module/financeManage'
import { systemManage } from './module/systemManage'
import Login from '@/views/login'
Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: '/home',
      name: 'home',
      component: () => import('@/views/home')
    },
    {
      path: '/spreadList',
      name: 'spreadList',
      component: () => import('@/views/spreadList')
    }, {
      path: '/spreadDetails',
      name: 'spreadDetails',
      component: () => import('@/views/spreadList/spreadDetails.vue')
    },
    {
      path: '/spreadDetail',
      name: 'spreadDetail',
      component: () => import('../views/spreadList/spreadDetails.vue')
    },
    ...storeManage,
    ...areaManage,
    ...orderManage,
    ...couponManage,
    ...materialManage,
    ...financeManage,
    ...systemManage]
  }
]

const router = new VueRouter({
  routes
})

export default router
